package com.example.common.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IntegerEnumValidator implements ConstraintValidator<IntegerEnum, Integer> {

    int[] range = {};

    @Override
    public void initialize(IntegerEnum arg0) {
        this.range = arg0.range();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext arg1) {
        for (int i : range) {
            if (value == i) {
                return true;
            }
        }

        return false;
    }

}